package com.njmaomao.gj.pyot.service;

import com.njmaomao.gj.pyot.common.Utils;
import com.njmaomao.gj.pyot.common.bean.dto.yto.*;
import com.njmaomao.gj.pyot.domain.yto.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class YtoAppService {

    @Autowired
    private YtoApiService ytoApiService;

    public Response orderCreate(RequestOrderDTO req) {
        String jsonStr = Utils.toJson(req);
        RequestOrder requestOrder = Utils.toObj(jsonStr, RequestOrder.class);
        return ytoApiService.orderCreate(requestOrder);
    }

    public Response orderCancel(UpdateInfoDTO req) {
        String jsonStr = Utils.toJson(req);
        UpdateInfo requestOrder = Utils.toObj(jsonStr, UpdateInfo.class);
        return ytoApiService.orderCancel(requestOrder);
    }

    public MianResponse eorderCreate(MianRequestOrderDTO req) {
        String jsonStr = Utils.toJson(req);
        MianRequestOrder requestOrder = Utils.toObj(jsonStr, MianRequestOrder.class);
        return ytoApiService.eorderCreate(requestOrder);
    }

    public MianResponse eOrdApply(MianRequestOrderDTO req) {
        String jsonStr = Utils.toJson(req);
        MianRequestOrder requestOrder = Utils.toObj(jsonStr, MianRequestOrder.class);
        return ytoApiService.eOrdApply(requestOrder);
    }

    public WaybillQueryResponse waybillQuery(WaybillQueryReqDTO req) {
        return ytoApiService.waybillQuery(req.getBillNo());
    }

    public ChargeQueryResponse chargeQuery(TransportInfoReqDTO req) {
        String jsonStr = Utils.toJson(req);
        TransportInfo transportInfo = Utils.toObj(jsonStr, TransportInfo.class);
        return ytoApiService.chargeQueryUrl(transportInfo);
    }
}
